
/* Use CMSE intrinsics */
#include <arm_cmse.h>
#include "RTE_Components.h"
#include CMSIS_device_header

/* TobudOS includes. */
#include "tos_secure_port_macros.h"

/* Start address of non-secure application. see mqtt_ns.sct RAM_BASE*/
#define Non_Secure_Start_Address		( 0x10000U )

/* typedef for non-secure Reset Handler. */
typedef void ( *non_secure_reset_handler_t )	( void ) __attribute__( ( cmse_nonsecure_call ) );
/*-----------------------------------------------------------*/

/* Boot into the non-secure code. */
void boot_non_secure( uint32_t non_secure_start_address );
/*-----------------------------------------------------------*/


void board_init_trustzone()
{

    
}


/* Secure main() */
int main( void )
{
	/*init the SAU register*/
	board_init_trustzone();
	
	/* Boot the non-secure code. */
	boot_non_secure( Non_Secure_Start_Address );

	/* Non-secure software does not return, this code is not executed. */
	for( ; ; )
	{
		/* Should not reach here. */
	}
}
/*-----------------------------------------------------------*/

void boot_non_secure( uint32_t non_secure_start_address )
{
	non_secure_reset_handler_t non_secure_reset_handler;

	/* Main Stack Pointer value for the non-secure side is the first entry in
	 * the non-secure vector table. Read the first entry and assign the same to
	 * the non-secure main stack pointer(MSP_NS). */
	secure_set_MSP_NS( *( ( uint32_t * )( non_secure_start_address ) ) );

	/* Non secure Reset Handler is the second entry in the non-secure vector
	 * table. Read the non-secure reset handler.
	 */
	non_secure_reset_handler = ( non_secure_reset_handler_t )( * ( ( uint32_t * ) ( ( non_secure_start_address ) + 4U ) ) );

	/* Start non-secure software application by jumping to the non-secure Reset Handler. */
	non_secure_reset_handler();
}
/*-----------------------------------------------------------*/

